

def SMA(object,period):
      
  return


def EMA(object,period,name):
  count = 1
  lastEMA = 0
  k = 2.0/(period+1)
  '''
  for price in reversed(object) :
    if count < period :
      lastEMA = lastEMA + price.Close
    elif count == period :
      lastEMA = (lastEMA + price.Close)/period
    else :
      lastEMA = price.Close*k + lastEMA*(1-k)
      ema_result.append({'date':price.Date,'ema':lastEMA})
    count = count + 1
  '''
  for price in reversed(object) :
    if count < period :
      lastEMA = lastEMA + price.Close
    elif count == period :
      lastEMA = (lastEMA + price.Close)/period
      price.__dict__[name] = lastEMA
    else :
      lastEMA = price.Close*k + lastEMA*(1-k)
      price.__dict__[name] = lastEMA
    count = count + 1    
  return object
